package com.tykhome.evernote.evernote2kindle.util;

import java.util.List;

import com.evernote.auth.EvernoteAuth;
import com.evernote.auth.EvernoteService;
import com.evernote.clients.ClientFactory;
import com.evernote.clients.NoteStoreClient;
import com.evernote.edam.error.EDAMSystemException;
import com.evernote.edam.error.EDAMUserException;
import com.evernote.edam.type.Notebook;
import com.evernote.thrift.TException;

public class NoteStoreUtil {
	private static final String DEVELOPERTOKEN = "S=s19:U=23b4c2:E=14c3ceb8259:C=144e53a565d:P=1cd:A=en-devtoken:V=2:H=c492326915f70a38ac191b6cbcfa3c98";
	
	private static NoteStoreClient noteStore;

	public static NoteStoreClient getNoteStore() {
		if (noteStore == null) {
			noteStore = createNoteStore();
		}
		return noteStore;
	}

	private static NoteStoreClient createNoteStore() {
		// Set up the NoteStore client 
		System.out.println(EvernoteService.YINXIANG);
		EvernoteAuth evernoteAuth = new EvernoteAuth(EvernoteService.YINXIANG, DEVELOPERTOKEN);
		ClientFactory factory = new ClientFactory(evernoteAuth);
		NoteStoreClient noteStore = null;
		try {
			noteStore = factory.createNoteStoreClient();
		} catch (EDAMUserException e) {
			e.printStackTrace();
		} catch (EDAMSystemException e) {
			e.printStackTrace();
		} catch (TException e) {
			e.printStackTrace();
		}
		return noteStore;
	}
	
	public static void main(String[] args) throws EDAMUserException, EDAMSystemException, TException {
		List<Notebook> notebooks = getNoteStore().listNotebooks();
		 
		for (Notebook notebook : notebooks) {
		  System.out.println("Notebook: " + notebook.getName());
		}
		
	}
	
}

